<?php
include_once( dirname(__FILE__).'/../../common/lib/Predis.php' );
class LoginController extends Yaf_Controller_Abstract
{
    /**
     * 登录验证码校验
     */
    public function indexAction()
    {
        $phoneNum = intval($_GET['phone_num']);
        $code = intval($_GET['code']);
        if (empty($phoneNum) || empty($code)) {
            show('phone or code is error', [], 200);
        }

        // redis code
        try {
            $redisCode = Predis::getInstance()->get(smsKey($phoneNum));
        } catch (\Exception $e) {
            echo $e->getMessage();
        }

        if ($redisCode == $code) {
            // 写入redis
            $data = [
                'user' => $phoneNum,
                'srcKey' => md5(userkey($phoneNum)),
                'time' => time(),
                'isLogin' => true,
            ];
            Predis::getInstance()->set(userkey($phoneNum), $data);

            show('ok', $data, 200);
        } else {
            show('login error', [], 200);
        }

        return FALSE;
    }
}


